package hsp.smallchange;

import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class SmallChange {
    public static void main(String[] args) {
        boolean loop = true;
        Scanner scanner = new Scanner(System.in);
        String key = "";
        String details = "------------------零钱通明细------------------";
        double money = 0;
        double balance = 0;
        Date date = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String note;

        do {
            System.out.println("=============零钱通菜单==================");
            System.out.println("\t\t\t1 零钱通明细");
            System.out.println("\t\t\t2 收益入账");
            System.out.println("\t\t\t3 消费");
            System.out.println("\t\t\t4 退出");
            System.out.println("请输入（1-4）:");
            key = scanner.next();
            //switch分支控制
            switch (key) {
                case "1":
                    System.out.println(details);
                    break;
                case "2":
                    System.out.print("收益入账金额:");
                    money = scanner.nextDouble();
                    //money校验
                    balance += money;
                    //拼接收益入账
                    details += "\n收益入账" + "\t +" + money + "\t " + sdf.format(new Date()) + "\t" + balance;
                    break;
                case "3":
                    System.out.println("请输入消费金额");
                    money = scanner.nextDouble();
                    System.out.println("消费说明:");
                    note = scanner.next();
                    balance -= money;
                    details += "\n" + note + "\t-" + money + "\t" + sdf.format(new Date()) + "\t" + balance;
                    break;
                case "4":
                    String choice = "";
                    while (true) {
                        System.out.println("你确定要退出吗？y/n");
                        choice = scanner.next();
                        if ("y".equals(choice) || "n".equals(choice)) {
                            break;
                        }
                    }
                    if ("y".equals(choice)) {
                        loop = false;
                    }
                    break;
                default:
                    System.out.println("输入有误\n\n\n\n\n");
            }
        } while (loop);

        System.out.println("---------退出了零钱通项目--------------");
    }
}
